Talk to the Cityのクラスタリング
2024-05-26
Talk to the Cityのクラスタリング
source
BERTopic
これが内部的にHDBSCANとUMAPを使うようだ
HDBSCAN
HDBSCAN — scikit-learn 1.5.0 documentation
HDBSCAN - Hierarchical Density-Based Spatial Clustering of Applications with Noise. Performs DBSCAN over varying epsilon values and integrates the result to find a clustering that gives the best stability over epsilon. This allows HDBSCAN to find clusters of varying densities (unlike DBSCAN), and be more robust to parameter selection.
UMAP
2025-06-06
o3.iconに解説させる
処理フロー
UMAP で高次元埋め込みを 2 次元に射影
HDBSCAN + BERTopic で 「トピックの確率」 を推定
射影後の 2D 座標を使って Spectral Clustering で 「最終クラスタ」 を決定
結果を clusters.csv に保存(各 argument を x–y 位置・確率・cluster-id 付きで出力)
UMAP後の座標データのSpectral Clusteringと、文書とUMAP後の座標データを内部でHDBSCANするBERTopicに与えたものの結果とを、前者のクラスタIDと後者のprobabilityで束ねて出力している。それクラスタが対応づかない可能性あるのでは?
code::
cluster_labels = spectral_model.fit_predict(umap_embeds)
result = topic_model.get_document_info(
docs=docs,
metadata={
**metadatas,
"x": umap_embeds:, 0,
"y": umap_embeds:, 1,
},
)
code::
result = result'arg-id', 'x', 'y', 'probability'
result'cluster-id' = cluster_labels